package org.example;

import java.io.*;
import java.nio.file.Path;

abstract class FilesParser extends FilesFinder {

    public FilesParser(String root, String regexp) throws IOException, DataFormatException {
        super(root, regexp);
        parse();
    }

    protected abstract void clear();

    private void parse() throws IOException, DataFormatException {
        clear();

        for (Path file : getFileList()) {
            parse(file);
        }
    }

    private void parse(Path file) throws IOException, DataFormatException {
        parse(
                new BufferedReader(
                        new FileReader(file.toFile())
                )
        );
    }

    protected abstract void parse(Reader reader) throws IOException, DataFormatException ;
}
